{ Statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1438
  Verdict: Accepted
}
uses
	SysUtils, Math;
 
var
	i, ls, cur : longint;
	s : string;
 
begin
	reset(input,'input.txt');
	rewrite(output,'output.txt');
	readln(s);
	ls := length(S);
	cur := 0;
	for i := 1 to ls do
		inc(cur, ord(s[i]) - 48);
	if cur mod 3 = 0 then write('YES') else write('NO');
end.